//
//  ChildDataViewController.m
//  IpadR
//
//  Created by edianzu on 2017/6/6.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChildDataViewController.h"
#import "ChildModel.h"
#import "ChildCell.h"
#import "ProjectCell.h"
@interface ChildDataViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIImagePickerControllerDelegate,SDDatePickerViewProtocol>
@property (nonatomic,strong)NSDictionary * allDataDictionary;
@property (nonatomic,strong)NSMutableArray * chosenChildArr;
@property (nonatomic,strong)NSMutableArray * projectArr;
@property (nonatomic,copy)NSString * AllStr;
@property (nonatomic,strong)NSMutableArray * dataArray;
@property (nonatomic,strong)ChildModel * sModel;
//@property (nonatomic,copy)NSString * isMent;
//@property (nonatomic,copy)NSString * isMot;
@property (nonatomic,assign)NSInteger intNum;//用来记录正在修改的位置
@property (nonatomic,assign)NSInteger theRow;//用来记录正在修改的位置
@end

@implementation ChildDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(change:) name:UITextFieldTextDidChangeNotification object:self.textField];//此处监听用于 输入数据时，有数据不让按钮可以点击
    // Do any additional setup after loading the view.
    //创建返回按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 100,40);
    [leftBtn setImage:[UIImage imageNamed:@"changeSchollLef"] forState:UIControlStateNormal];
    [leftBtn setTitle:@"切换班级" forState:UIControlStateNormal];
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];;
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = 15;
    //将两个BarButtonItem都返回给NavigationItem
    self.navigationItem.leftBarButtonItems = @[spaceItem,leftBarBtn];
    
    //创建右边按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 100,40);
    [rightBtn setImage:[UIImage imageNamed:@"navRightBtn"] forState:UIControlStateNormal];
    [rightBtn setTitle:@"添加成员" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightBarBtn = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];;
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItemm = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //将宽度设为负值
    spaceItemm.width = 5;
    //将两个BarButtonItem都返回给NavigationItem
    self.navigationItem.rightBarButtonItems = @[spaceItemm,rightBarBtn];
    
    self.title = self.mainTitle;
    NSLog(@"%@",self.KId);
    self.view.backgroundColor = [HexColor colorWithHexString:Gray_Back];
    [self getData];
    [self createUI];
    
    
    
    //添加键盘监听事件
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

-(void)getData{
    NSLog(@"获取数据中");
    ///////////////////////////获取本班的孩子
    NSString* str = [[NSUserDefaults standardUserDefaults]objectForKey:@"AllData"];//获取全部数据
    //    NSLog(@"eee===%@",str);
    NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
    _allDataDictionary = [[NSDictionary alloc]init];
    _allDataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    NSArray * childArr = [[NSArray alloc]init];//机构所有孩子
    childArr = _allDataDictionary[@"Children"];

    _chosenChildArr = [NSMutableArray new];// 本班的孩子
    
    for (NSDictionary * dic in childArr) {
        self.sModel = [ChildModel modelWithDictionary:dic];
        if ([self.sModel.ClassId  isEqual: self.KId]) {
            [_chosenChildArr addObject:self.sModel];
        }
    }
    //将缺席的孩子放在最后
    NSMutableArray * absenceBabyArr = [[NSMutableArray alloc]init];
    for (ChildModel * mod in _chosenChildArr.reverseObjectEnumerator) {
        if (mod.IsAbsense) {
            [absenceBabyArr addObject:mod];
            [_chosenChildArr removeObject:mod];
        }
    }
//    for (ChildModel * mod in chosenChildArr) {
//        if (mod.IsAbsense) {
//            [chosenChildArr removeObject:mod];
//        }
//    }
    for (ChildModel * mod in absenceBabyArr) {
        
        [_chosenChildArr addObject:mod];
    }
    
    
    ///////////////////////////获取选择好的项目
    NSMutableArray * arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"testProject"];//从本地取出项目组
    _projectArr = [[NSMutableArray alloc] init];//用来装项目组的ARR
    for (NSArray * dataarr in arr) {
        NSMutableArray * proDetailArr = [[NSMutableArray alloc] init];
        for (NSDictionary * dic in dataarr) {
            NSMutableDictionary * dictt = [NSMutableDictionary dictionaryWithDictionary:dic];
            //            [dictt setValue:@10 forKey:@"proValue"];
            [proDetailArr addObject:dictt];
            
        }
        [_projectArr addObject:proDetailArr];
    }
    //每个孩子都有同样的项目组，创建字典 放入数据源
    self.dataArray = [[NSMutableArray alloc]init];
    for (int i = 0; i<_chosenChildArr.count; i++) {
        NSMutableDictionary * dictionary = [NSMutableDictionary new];
        [dictionary setValue:_chosenChildArr[i] forKey:@"ChildName"];
        [dictionary setValue:_projectArr forKey:@"Project"];
        [self.dataArray addObject:dictionary];
    }
//    NSLog(@"%ld,.,.,.,.%ld",chosenChildArr.count,self.dataArray.count);
}



-(void)createUI{
    //得到已经测试的人数
    NSInteger testedNum = [self getTestedBabyWithModelArray:_chosenChildArr andProjectArray:_projectArr];
    NSLog(@"testesd %ld",testedNum);
//    self.processLabel.text = [NSString stringWithFormat:@"班级测试完成度(%ld/%ld)",testedNum,_chosenChildArr.count];
    //完成进度
    self.processLabel = [[UILabel alloc]init];
    self.processLabel.textColor = UIColorFromRGB(144, 144, 144);
    [self.processLabel setTextAlignment:NSTextAlignmentCenter];
    self.processLabel.text = [NSString stringWithFormat:@"班级测试完成度(%ld/%ld)",testedNum,_chosenChildArr.count];
    self.processLabel.font = [UIFont boldSystemFontOfSize:13*AutoScaleHorizontal];
    [self.view addSubview:self.processLabel];
    [self.processLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).with.offset(20*AutoScaleVertical);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(300*AutoScaleHorizontal, 15*AutoScaleVertical));
    }];
    //左侧孩子列表
    self.childTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 200*AutoScaleHorizontal, 10) style:UITableViewStylePlain];
    self.childTable.backgroundColor = [UIColor whiteColor];
    [self.childTable registerClass:[ChildCell class] forCellReuseIdentifier:@"ChildCell"];
    self.childTable.showsVerticalScrollIndicator =NO;
    self.childTable.dataSource = self;
    self.childTable.delegate = self;
    self.childTable.rowHeight = UITableViewAutomaticDimension;
    self.childTable.estimatedRowHeight = 500;
    self.childTable.layer.borderColor = UIColorFromRGB(231, 231, 231).CGColor;
    self.childTable.layer.borderWidth = 1;
    self.childTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    //默认选中第一行
    NSIndexPath *firstPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.childTable selectRowAtIndexPath:firstPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    
    [self.view addSubview:self.childTable];
    [self.childTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).with.offset(55*AutoScaleVertical);
        make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(-70*AutoScaleVertical);
        make.left.mas_equalTo(self.view.mas_left).with.offset(55*AutoScaleHorizontal);
        make.width.mas_equalTo(200*AutoScaleHorizontal);
    }];
    
    //右侧项目列表
    self.projectTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 650*AutoScaleHorizontal, 10) style:UITableViewStylePlain];
    self.projectTable.backgroundColor = [UIColor whiteColor];
    [self.projectTable registerClass:[ProjectCell class] forCellReuseIdentifier:@"ProjectCell"];
    self.projectTable.showsVerticalScrollIndicator =NO;
    self.projectTable.separatorStyle = UITableViewCellEditingStyleNone;
    self.projectTable.dataSource = self;
    self.projectTable.delegate = self;
    self.projectTable.rowHeight = UITableViewAutomaticDimension;
    self.projectTable.estimatedRowHeight = 500;
    self.projectTable.layer.borderColor = UIColorFromRGB(231, 231, 231).CGColor;
    self.projectTable.layer.borderWidth = 1;
    self.projectTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.projectTable];
    [self.projectTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).with.offset(55*AutoScaleVertical);
        make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(-70*AutoScaleVertical);
        make.right.mas_equalTo(self.view.mas_right).with.offset(-55*AutoScaleHorizontal);
        make.width.mas_equalTo(650*AutoScaleHorizontal);
        
    }];
}
#pragma mark tableView delegate 
//禁止TABLEVIEW 下拉顶部超过SCREEN
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    NSLog(@"%f",self.childTable.contentOffset.y);
    if (self.childTable.contentOffset.y <= 0) {
        self.childTable.bounces = NO;
        NSLog(@"禁止下拉");
    }
    else
        if (self.childTable.contentOffset.y >= 0){
            self.childTable.bounces = YES;
            NSLog(@"允许上拉");
        }
    
    ////////////////////////////////////////////
    if (self.projectTable.contentOffset.y <= 0) {
        self.projectTable.bounces = NO;
        NSLog(@"禁止下拉");
    }
    else
        if (self.projectTable.contentOffset.y >= 0){
            self.projectTable.bounces = YES;
            NSLog(@"允许上拉");
        }
    
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    ////////////////孩子列表
    if (tableView ==self.childTable) {
        UIView * view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        UIImageView * img = [[UIImageView alloc]init];
        img.image = [UIImage imageNamed:@"classMember"];
        [view addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(view.mas_left).with.offset(50*AutoScaleHorizontal);
            make.centerY.mas_equalTo(view.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(12*AutoScaleHorizontal, 12*AutoScaleVertical));
        }];
        UILabel * label = [[UILabel alloc]init];
        label.font = [UIFont systemFontOfSize:15*AutoScaleHorizontal];
        label.text = @"班级成员";
        label.textColor = UIColorFromRGB(88, 88, 88);
        [view addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(img.mas_right).with.offset(20*AutoScaleHorizontal);
            make.centerY.mas_equalTo(view.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(90*AutoScaleHorizontal, 30*AutoScaleVertical));
        }];
        
        UIView * line = [[UIView alloc]init];
        line.backgroundColor = UIColorFromRGB(243, 243, 243);
        [view addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(view.mas_bottom);
            make.width.mas_equalTo(view);
            make.left.mas_equalTo(view.mas_left);
            make.height.mas_equalTo(2*AutoScaleVertical);
        }];
        return view;
    }
    ////////////////项目列表
    else if (tableView ==self.projectTable) {
            UIView * view = [[UIView alloc]init];
            view.backgroundColor = [UIColor whiteColor];
            UILabel * label = [[UILabel alloc]init];
        //取到孩子列表的选中项
        NSIndexPath *indexPath = [self.childTable indexPathForSelectedRow];
        NSMutableDictionary * dic = self.dataArray[indexPath.row];
        ChildModel * model =[dic objectForKey:@"ChildName"];
        label.text =model.ChildName;
            label.font = [UIFont boldSystemFontOfSize:14*AutoScaleHorizontal];
            label.textColor = UIColorFromRGB(88, 88, 88);
            [view addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(view.mas_left).with.offset(15*AutoScaleHorizontal);
                make.centerY.mas_equalTo(view.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 20*AutoScaleVertical));
            }];
        
            UIButton * btn = [[UIButton alloc]init];
        //如果选中项是缺席，则按钮换图片
        
        if (model.IsAbsense) {
            //如果缺席 设置为“取消缺席”
            [btn setBackgroundImage:[UIImage imageNamed:@"isNoAbsence"] forState:UIControlStateNormal];
        }else{
            [btn setBackgroundImage:[UIImage imageNamed:@"isAbsence"] forState:UIControlStateNormal];
        }
        [btn addTarget:self action:@selector(pressAbsence) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(view.mas_right).with.offset(-15*AutoScaleHorizontal);
                make.centerY.mas_equalTo(view.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(75*AutoScaleHorizontal, 25*AutoScaleVertical));
            }];
            
            UIView * line = [[UIView alloc]init];
            line.backgroundColor = UIColorFromRGB(243, 243, 243);
            [view addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(view.mas_bottom);
                make.width.mas_equalTo(view);
                make.left.mas_equalTo(view.mas_left);
                make.height.mas_equalTo(2*AutoScaleVertical);
            }];
            return view;
    }else{
    
    return nil;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50*AutoScaleVertical;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView ==self.childTable) {
        return 80*AutoScaleVertical;
    }else{
    
    
    NSIndexPath *index = [self.childTable indexPathForSelectedRow];
    NSMutableDictionary * dict = self.dataArray[index.row];
        ChildModel * model = [dict objectForKey:@"ChildName"];
        //如果缺席
        if (model.IsAbsense ) {
        return 380*AutoScaleVertical;
        }else{
            NSMutableArray * array = [NSMutableArray new];
            array = [dict objectForKey:@"Project"][indexPath.row];
        return (30+75*array.count)*AutoScaleVertical;
        }
    }
}

//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    ////////////////孩子列表
    if (tableView == self.childTable) {
        return self.dataArray.count;
    }
    ////////////////项目列表
    if (tableView == self.projectTable) {
        NSIndexPath *indexPath = [self.childTable indexPathForSelectedRow];
        NSMutableDictionary * dic = self.dataArray[indexPath.row];
//        NSMutableDictionary * dic = self.dataArray[section];
        ChildModel * model = [dic objectForKey:@"ChildName"];
        if (model.IsAbsense) {
            return 1;
        }else{
        NSMutableArray * arr = [dic objectForKey:@"Project"];
        return arr.count;
    }
    }else{
        return 0;
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ////////////////孩子列表
    if (tableView == self.childTable) {
    static NSString *CMainCell = @"ChildCell";
        ChildCell * cell = [tableView dequeueReusableCellWithIdentifier:CMainCell forIndexPath:indexPath];;
        
    if (cell == nil) {
        cell = [[ChildCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier: CMainCell] ;
//        cell.selectedBackgroundView.backgroundColor = [HexColor colorWithHexString:@"#00bcab"];
//        cell.textLabel.highlightedTextColor = [HexColor colorWithHexString:@"#fffff"];
    }
//    else {
//        while  ([cell.contentView.subviews lastObject]!= nil){
//            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
//        }
//    }
    
    NSMutableDictionary * dict = self.dataArray[indexPath.row];
    [cell reSetCell:dict andNum:indexPath.row];
    return cell;
    }
    ////////////////项目列表
    else {
        static NSString *PMainCell = @"ProjectCell";
        ProjectCell * cell = [tableView dequeueReusableCellWithIdentifier:PMainCell ];
        if (cell == nil) {
            cell = [[ProjectCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier: PMainCell] ;
        }
        __weak typeof(self) weak_self = self;
        cell.action = ^(NSInteger integer) {
//            NSLog(@"aCTION的INTEGER   %d",integer);
            [weak_self createInputValueView:integer andRow:indexPath.row];
        };
//        NSMutableArray * array = [NSMutableArray new];
//        array = [dict objectForKey:@"Project"][num];
        NSIndexPath *index = [self.childTable indexPathForSelectedRow];
        NSMutableDictionary * dict = self.dataArray[index.row];
//        NSMutableDictionary * dict = self.dataArray[indexPath.section];
        [cell relayoutCellWithNum:indexPath.row andDic:dict];
        
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.childTable) {
        [self.projectTable reloadData];
    }
    NSMutableDictionary * dict = self.dataArray[indexPath.row];
    ChildModel * model = [dict objectForKey:@"ChildName"];
    NSLog(@"childName = %@",model.ChildName);
    
}
#pragma mark  按钮方法们
#pragma mark  点击输入数值相关
-(void)createInputValueView:(NSInteger)integer andRow:(NSInteger)row{
    
    self.intNum = integer;
    self.theRow = row;
    
    NSIndexPath *index = [self.childTable indexPathForSelectedRow];
    NSMutableDictionary * dict = self.dataArray[index.row];
    ChildModel * model = [dict objectForKey:@"ChildName"];
    NSMutableArray * array = [NSMutableArray new];
    array = [dict objectForKey:@"Project"][row];
    NSMutableDictionary * dic = array[integer];
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    self.baseView = [[UIView alloc]init];
    self.baseView.backgroundColor = [UIColor whiteColor];
    [window addSubview:self.baseView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(window.mas_top).with.offset(50*AutoScaleVertical);
        make.centerY.mas_equalTo(window.mas_centerY);
        make.centerX.mas_equalTo(window.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 300*AutoScaleVertical));
    }];
    
    UILabel * label = [[UILabel alloc]init];
    label.text = model.ChildName;
    label.textColor = [UIColor blackColor];
    [label setTextAlignment:NSTextAlignmentCenter];
    label.font = [UIFont boldSystemFontOfSize:15*AutoScaleHorizontal];
    [self.baseView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.baseView.mas_centerX);
        make.top.mas_equalTo(self.baseView.mas_top).with.offset(10*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    UIButton * cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelBtn setImage:[UIImage imageNamed:@"iconCancel"] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(pressCancel) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label.mas_centerY);
        make.right.mas_equalTo(self.baseView.mas_right).with.offset(-30*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(30*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    UIView * lineview = [[UIView alloc]init];
    lineview.backgroundColor =UIColorFromRGB(243, 243, 243);
    [self.baseView addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.baseView);
        make.top.mas_equalTo(label.mas_bottom).with.offset(10*AutoScaleVertical);
        make.height.mas_equalTo(1*AutoScaleVertical);
    }];
    
    self.labelPro = [[UILabel alloc]init];
    self.labelPro.text = [dic objectForKey:@"proName"];
    self.labelPro.textColor = [UIColor blackColor];
    [self.labelPro setTextAlignment:NSTextAlignmentRight];
    self.labelPro.font = [UIFont systemFontOfSize:14*AutoScaleHorizontal];
    [self.baseView addSubview:self.labelPro];
    [self.labelPro mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.baseView.mas_left).with.offset(50*AutoScaleHorizontal);
        make.top.mas_equalTo(lineview.mas_bottom).with.offset(30*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.textField = [[UITextField alloc]init];
    self.textField.delegate =self;
    self.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    self.textField.layer.borderWidth = 1;
    self.textField.layer.borderColor =UIColorFromRGB(243, 243, 243).CGColor;
    [self.baseView addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.labelPro.mas_right).with.offset(5*AutoScaleHorizontal);
        make.top.mas_equalTo(lineview.mas_bottom).with.offset(25*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    [self.textField becomeFirstResponder];
    
    
    //单位
    self.labelUnit = [[UILabel alloc]init];
    if ([[dic objectForKey:@"proNum"]  isEqualToString: @"3"]||[[dic objectForKey:@"proNum"]  isEqualToString: @"6"]||[[dic objectForKey:@"proNum"]  isEqualToString: @"8"]) {
        self.labelUnit.text =@"s";
    }
    if ([[dic objectForKey:@"proNum"]  isEqualToString: @"1"]||[[dic objectForKey:@"proNum"]  isEqualToString: @"4"]||[[dic objectForKey:@"proNum"]  isEqualToString: @"5"]){
        self.labelUnit.text =@"cm";
    }
    if ([[dic objectForKey:@"proNum"]  isEqualToString: @"2"]) {
        self.labelUnit.text =@"kg";
    }
    if ([[dic objectForKey:@"proNum"]  isEqualToString: @"7"]) {
        self.labelUnit.text =@"m";
    }
    self.labelUnit.textColor = [UIColor blackColor];
    [self.labelUnit setTextAlignment:NSTextAlignmentLeft];
    self.labelUnit.font = [UIFont systemFontOfSize:14*AutoScaleHorizontal];
    [self.baseView addSubview:self.labelUnit];
    [self.labelUnit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.textField.mas_right);
        make.centerY.mas_equalTo(self.labelPro.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.ismenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.ismenBtn.selected = NO;
    [self.ismenBtn addTarget:self action:@selector(pressMENT) forControlEvents:UIControlEventTouchUpInside];
    [self.ismenBtn setTitle:@"心理发展指数" forState:UIControlStateNormal];
    [self.ismenBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.ismenBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [self.ismenBtn setImage:[UIImage imageNamed:@"noValue"] forState:UIControlStateNormal];
    [self.ismenBtn setImage:[UIImage imageNamed:@"noValueS"] forState:UIControlStateSelected];
    [self.baseView addSubview:self.ismenBtn];
    [self.ismenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.baseView.mas_left).with.offset(75*AutoScaleHorizontal);
        make.top.mas_equalTo(self.textField.mas_bottom).with.offset(50*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.ismotBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.ismotBtn.selected = NO;
    [self.ismotBtn addTarget:self action:@selector(pressMOT) forControlEvents:UIControlEventTouchUpInside];
    [self.ismotBtn setTitle:@"动作发展指数" forState:UIControlStateNormal];
    [self.ismotBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.ismotBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [self.ismotBtn setImage:[UIImage imageNamed:@"noValue"] forState:UIControlStateNormal];
    [self.ismotBtn setImage:[UIImage imageNamed:@"noValueS"] forState:UIControlStateSelected];
    [self.baseView addSubview:self.ismotBtn];
    [self.ismotBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.ismenBtn.mas_right).with.offset(75*AutoScaleHorizontal);
        make.top.mas_equalTo(self.textField.mas_bottom).with.offset(50*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    //身高和体重没有 心理和动作因素
    if ([[dic objectForKey:@"proNum"]  isEqualToString: @"1"]||[[dic objectForKey:@"proNum"]  isEqualToString: @"2"]){
        self.ismenBtn.hidden =YES;
        self.ismotBtn.hidden = YES;
    }
    
    self.saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.saveBtn addTarget:self action:@selector(pressSave) forControlEvents:UIControlEventTouchUpInside];
    [self.saveBtn setBackgroundImage:[UIImage imageNamed:@"saveBtn"] forState:UIControlStateNormal];
    [self.baseView addSubview:self.saveBtn];
    [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.baseView.mas_centerX);
        make.top.mas_equalTo(self.ismenBtn.mas_bottom).with.offset(50*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    
}
//
-(void)change:(NSNotification *)notification
{
    if (self.textField.text.length > 0) {
        self.ismenBtn.userInteractionEnabled = NO;
        self.ismotBtn.userInteractionEnabled = NO;
        self.ismenBtn.alpha = 0.3;
        self.ismotBtn.alpha = 0.3;
    }else
    {
        self.ismenBtn.userInteractionEnabled = YES;
        self.ismotBtn.userInteractionEnabled = YES;
        self.ismenBtn.alpha = 1;
        self.ismotBtn.alpha = 1;
    }
    
}

-(void)pressCancel{
    NSLog(@"取消");
    [self.textField resignFirstResponder];
    [self.nameText resignFirstResponder];
    [self.backView removeFromSuperview];
    [self.baseView removeFromSuperview];
}
//心理
-(void)pressMENT{
    NSLog(@"心理");
    [self.textField resignFirstResponder];
    if (self.ismenBtn.selected ==NO) {
//        self.isMent = @"1";
//        self.isMot = @"0";
        self.textField.userInteractionEnabled = NO;
        self.ismenBtn.selected = YES;
        self.ismotBtn.selected = NO;
        self.labelPro.textColor = UIColorFromRGB(243, 243, 243);
        self.labelUnit.textColor = UIColorFromRGB(243, 243, 243);
    }else{
//        self.isMent = @"0";
        self.textField.userInteractionEnabled = YES;
        self.ismenBtn.selected = NO;
        self.labelPro.textColor = [UIColor blackColor];
        self.labelUnit.textColor = [UIColor blackColor];
    }
    
}
//动作
-(void)pressMOT{
    NSLog(@"动作");
    [self.textField resignFirstResponder];
    if (self.ismotBtn.selected ==NO) {
//        self.isMent = @"0";
//        self.isMot = @"1";
        self.textField.userInteractionEnabled = NO;
        self.ismenBtn.selected = NO;
        self.ismotBtn.selected = YES;
        self.labelPro.textColor = UIColorFromRGB(243, 243, 243);
        self.labelUnit.textColor = UIColorFromRGB(243, 243, 243);
    }else{
//        self.isMot = @"0";
        self.textField.userInteractionEnabled = YES;
        self.ismotBtn.selected = NO;
        self.labelPro.textColor = [UIColor blackColor];
        self.labelUnit.textColor = [UIColor blackColor];
    }
}
//保存
-(void)pressSave{
    //找到当前正在更改的项目
//    NSLog(@"保存%ld,%ld",self.intNum,self.theRow);
    NSIndexPath *index = [self.childTable indexPathForSelectedRow];
    NSMutableDictionary * dict = self.dataArray[index.row];
    ChildModel * model = [dict objectForKey:@"ChildName"];////////模型
    NSMutableArray * array = [NSMutableArray new];
    array = [dict objectForKey:@"Project"][self.theRow];/////////选中的项目数组，内含本组多个字典(具体项目pronum proname)
    NSMutableDictionary * dic = array[self.intNum];
    //当心理健康指数为YES 时:
    if (self.ismenBtn.selected == YES) {
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"3"]){
            model.IsMentalShuttleRun = YES;
            model.IsMotorShuttleRun = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMotorShuttleRun"];
                    [dic setObject:boolNum forKey:@"IsMentalShuttleRun"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
           
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"4"]){
            model.IsMentalSitReach = YES;
            model.IsMotorSitReach = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMotorSitReach"];
                    [dic setObject:boolNum forKey:@"IsMentalSitReach"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"5"]){
            model.IsMentalBroadJump = YES;
            model.IsMotorBroadJump = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMotorBroadJump"];
                    [dic setObject:boolNum forKey:@"IsMentalBroadJump"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"6"]){
            model.IsMentalDoubleJump = YES;
            model.IsMotorDoubleJump = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMotorDoubleJump"];
                    [dic setObject:boolNum forKey:@"IsMentalDoubleJump"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"7"]){
            model.IsMentalThrow = YES;
            model.IsMotorThrow = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMotorThrow"];
                    [dic setObject:boolNum forKey:@"IsMentalThrow"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"8"]){
            model.IsMentalBalance = YES;
            model.IsMotorBalance = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMotorBalance"];
                    [dic setObject:boolNum forKey:@"IsMentalBalance"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        
    }
    
    //当动作健康指数为YES 时:
     else if (self.ismotBtn.selected == YES) {
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"3"]){
            model.IsMotorShuttleRun = YES;
            model.IsMentalShuttleRun = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMentalShuttleRun"];
                    [dic setObject:boolNum forKey:@"IsMotorShuttleRun"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"4"]){
            model.IsMotorSitReach = YES;
            model.IsMentalSitReach = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMentalSitReach"];
                    [dic setObject:boolNum forKey:@"IsMotorSitReach"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"5"]){
            model.IsMotorBroadJump = YES;
            model.IsMentalBroadJump = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMentalBroadJump"];
                    [dic setObject:boolNum forKey:@"IsMotorBroadJump"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"6"]){
            model.IsMotorDoubleJump = YES;
            model.IsMentalDoubleJump = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMentalDoubleJump"];
                    [dic setObject:boolNum forKey:@"IsMotorDoubleJump"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"7"]){
            model.IsMotorThrow = YES;
            model.IsMentalThrow = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMentalThrow"];
                    [dic setObject:boolNum forKey:@"IsMotorThrow"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"8"]){
            model.IsMotorBalance = YES;
            model.IsMentalBalance = NO;
            [self.textField resignFirstResponder];
            [self.backView removeFromSuperview];
            [self.baseView removeFromSuperview];
            [dict removeObjectForKey:@"ChildName"];
            [dict setObject:model forKey:@"ChildName"];
            [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
            //将改变过得数据源从新存储到本地
            NSMutableDictionary * dictNew = self.dataArray[index.row];
            ChildModel * mod = [dictNew objectForKey:@"ChildName"];
            for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                    NSNumber * boolNum = [NSNumber numberWithBool:YES];
                    NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                    [dic setObject:noBoolNum forKey:@"IsMentalBalance"];
                    [dic setObject:boolNum forKey:@"IsMotorBalance"];
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
            }
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
            [user removeObjectForKey:@"AllData"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
            
            [self.projectTable reloadData];
            [self.childTable reloadData];
            //让列表不要会第一列
            [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

        }
         
    }
    
    
    else                      {
        
    if (self.textField.text.length == 0) {
        [self.textField resignFirstResponder];
        [self showMessage:@"请输入测量数据"];
        
    }else         {
        if ([[dic objectForKey:@"proNum"] isEqualToString: @"1"]){
            if ([self.textField.text integerValue]<50 || [self.textField.text integerValue]>160) {
                [self.textField resignFirstResponder];
                [self showMessage:@"身高的数值范围在50至160cm之间"];
            }else{
                model.Height = self.textField.text;
                
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        [dic setObject:self.textField.text forKey:@"Height"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
//                        [dic setObject:noBoolNum forKey:@"IsMentalBalance"];
//                        [dic setObject:noBoolNum forKey:@"IsMotorBalance"];
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                
                
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

                 }
        }
        if ([[dic objectForKey:@"proNum"] isEqualToString: @"2"]){
            if ([self.textField.text integerValue]<5 || [self.textField.text integerValue]>60) {
                [self.textField resignFirstResponder];
                [self showMessage:@"体重的数值范围在5至60kg之间"];
            }else{
                model.Weight = self.textField.text;
                
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        [dic setObject:self.textField.text forKey:@"Weight"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                        //                        [dic setObject:noBoolNum forKey:@"IsMentalBalance"];
                        //                        [dic setObject:noBoolNum forKey:@"IsMotorBalance"];
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"3"]){
            if ([self.textField.text floatValue]< 4.0 || [self.textField.text floatValue]>60.0) {
                [self.textField resignFirstResponder];
                [self showMessage:@"折返跑的数值范围在4至60s之间"];
            }else{
                model.ShuttleRun = self.textField.text;
                model.IsMentalShuttleRun = NO;
                model.IsMotorShuttleRun = NO;
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                        [dic setObject:self.textField.text forKey:@"ShuttleRun"];
                        [dic setObject:noBoolNum forKey:@"IsMentalShuttleRun"];
                        [dic setObject:noBoolNum forKey:@"IsMotorShuttleRun"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];

                
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
            
        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"4"]){
            if ([self.textField.text integerValue]< -10 || [self.textField.text integerValue]>25) {
                [self.textField resignFirstResponder];
                [self showMessage:@"坐位体前屈的数值范围在-10至25cm之间"];
            }else{
                model.SitReach = self.textField.text;
                model.IsMentalSitReach = NO;
                model.IsMotorSitReach = NO;
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                        [dic setObject:self.textField.text forKey:@"SitReach"];
                        [dic setObject:noBoolNum forKey:@"IsMentalSitReach"];
                        [dic setObject:noBoolNum forKey:@"IsMotorSitReach"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
            
        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"5"]){
            if ([self.textField.text integerValue]< 15 || [self.textField.text integerValue]> 200) {
                [self.textField resignFirstResponder];
                [self showMessage:@"立定跳远的数值范围在15至200cm之间"];
            }else{
                model.BroadJump = self.textField.text;
                model.IsMentalBroadJump = NO;
                model.IsMotorBroadJump = NO;
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                        [dic setObject:self.textField.text forKey:@"BroadJump"];
                        [dic setObject:noBoolNum forKey:@"IsMentalBroadJump"];
                        [dic setObject:noBoolNum forKey:@"IsMotorBroadJump"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
            
        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"6"]){
            if ([self.textField.text floatValue]< 3.0 || [self.textField.text floatValue]>40.0) {
                [self.textField resignFirstResponder];
                [self showMessage:@"连续跳的数值范围在3至40s之间"];
            }else{
                model.DoubleJump = self.textField.text;
                model.IsMentalDoubleJump = NO;
                model.IsMotorDoubleJump = NO;
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                        [dic setObject:self.textField.text forKey:@"DoubleJump"];
                        [dic setObject:noBoolNum forKey:@"IsMentalDoubleJump"];
                        [dic setObject:noBoolNum forKey:@"IsMotorDoubleJump"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
            
        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"7"]){
            if ([self.textField.text floatValue]< 1.0 || [self.textField.text floatValue]>20.0) {
                [self.textField resignFirstResponder];
                [self showMessage:@"网球掷远的数值范围在1至20m之间"];
            }else{
                model.Throw = self.textField.text;
                model.IsMentalThrow = NO;
                model.IsMotorThrow = NO;
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                        [dic setObject:self.textField.text forKey:@"Throw"];
                        [dic setObject:noBoolNum forKey:@"IsMentalThrow"];
                        [dic setObject:noBoolNum forKey:@"IsMotorThrow"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
            
        }
        if ([[dic objectForKey:@"proNum"]  isEqualToString: @"8"]){
            if ([self.textField.text floatValue]< 2.0 || [self.textField.text floatValue]>120.0) {
                [self.textField resignFirstResponder];
                [self showMessage:@"走平衡木的数值范围在2至120s之间"];
            }else{
                model.Balance = self.textField.text;
                model.IsMentalBalance = NO;
                model.IsMotorBalance = NO;
                [self.textField resignFirstResponder];
                [self.backView removeFromSuperview];
                [self.baseView removeFromSuperview];
                [dict removeObjectForKey:@"ChildName"];
                [dict setObject:model forKey:@"ChildName"];
                [self.dataArray replaceObjectAtIndex:index.row withObject:dict];
                //将改变过得数据源从新存储到本地
                NSMutableDictionary * dictNew = self.dataArray[index.row];
                ChildModel * mod = [dictNew objectForKey:@"ChildName"];
                for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
                    if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                        NSNumber * noBoolNum = [NSNumber numberWithBool:NO];
                        [dic setObject:self.textField.text forKey:@"Balance"];
                        [dic setObject:noBoolNum forKey:@"IsMentalBalance"];
                        [dic setObject:noBoolNum forKey:@"IsMotorBalance"];
                        [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                    }
                }
                //转换格式
                NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
                self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
                [user removeObjectForKey:@"AllData"];
                [user setObject:self.AllStr forKey:@"AllData"];
                [user synchronize];
                [self.projectTable reloadData];
                [self.childTable reloadData];
                //让列表不要会第一列
                [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];

            }
            
        }
                   }
                                }
    //得到已经测试的人数
    [self getData];
    NSInteger testedNum = [self getTestedBabyWithModelArray:_chosenChildArr andProjectArray:_projectArr];
    NSLog(@"testesd %ld",testedNum);
    self.processLabel.text = [NSString stringWithFormat:@"班级测试完成度(%ld/%ld)",testedNum,_chosenChildArr.count];
    
}

#pragma mark 因故缺席相关
-(void)pressAbsence{
    NSLog(@"因故缺席");
    NSIndexPath *index = [self.childTable indexPathForSelectedRow];
    NSMutableDictionary * dict = self.dataArray[index.row];
    ChildModel * model = [dict objectForKey:@"ChildName"];////////模型
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    self.baseView = [[UIView alloc]init];
    self.baseView.backgroundColor = [UIColor whiteColor];
    [window addSubview:self.baseView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(window.mas_centerY);
        make.centerX.mas_equalTo(window.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 300*AutoScaleVertical));
    }];
    
    UILabel * label = [[UILabel alloc]init];
    label.text = @"提示";
    label.textColor = [UIColor blackColor];
    [label setTextAlignment:NSTextAlignmentCenter];
    label.font = [UIFont boldSystemFontOfSize:15*AutoScaleHorizontal];
    [self.baseView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.baseView.mas_centerX);
        make.top.mas_equalTo(self.baseView.mas_top).with.offset(10*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    UIView * lineview = [[UIView alloc]init];
    lineview.backgroundColor =UIColorFromRGB(243, 243, 243);
    [self.baseView addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.baseView);
        make.top.mas_equalTo(label.mas_bottom).with.offset(10*AutoScaleVertical);
        make.height.mas_equalTo(1*AutoScaleVertical);
    }];
    
    self.labelPro = [[UILabel alloc]init];
    if (model.IsAbsense) {
        self.labelPro.text = @"孩子回来了吗?";
    }else{
        self.labelPro.text = @"确定孩子因故缺席吗?";
    }
    
    self.labelPro.textColor = [UIColor blackColor];
    [self.labelPro setTextAlignment:NSTextAlignmentCenter];
    self.labelPro.font = [UIFont boldSystemFontOfSize:14*AutoScaleHorizontal];
    [self.baseView addSubview:self.labelPro];
    [self.labelPro mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.baseView.mas_centerX);
        make.top.mas_equalTo(lineview.mas_bottom).with.offset(50*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(300*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.ismenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.ismenBtn addTarget:self action:@selector(letMeThink) forControlEvents:UIControlEventTouchUpInside];
    [self.ismenBtn setBackgroundImage:[UIImage imageNamed:@"noBtn"] forState:UIControlStateNormal];
    [self.baseView addSubview:self.ismenBtn];
    [self.ismenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.baseView.mas_left).with.offset(100*AutoScaleHorizontal);
        make.top.mas_equalTo(self.labelPro.mas_bottom).with.offset(70*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.ismotBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.ismotBtn addTarget:self action:@selector(yeahMan) forControlEvents:UIControlEventTouchUpInside];
    [self.ismotBtn setBackgroundImage:[UIImage imageNamed:@"yesBtn"] forState:UIControlStateNormal];
    [self.baseView addSubview:self.ismotBtn];
    [self.ismotBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.baseView.mas_right).with.offset(-100*AutoScaleHorizontal);
        make.top.mas_equalTo(self.labelPro.mas_bottom).with.offset(70*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
}
//我再想想
-(void)letMeThink{
    [self.backView removeFromSuperview];
    [self.baseView removeFromSuperview];
}
//确定缺席
-(void)yeahMan{
    
    //找到当前正在更改的项目
    //    NSLog(@"保存%ld,%ld",self.intNum,self.theRow);
    NSIndexPath *index = [self.childTable indexPathForSelectedRow];
    NSMutableDictionary * dict = self.dataArray[index.row];
    ChildModel * model = [dict objectForKey:@"ChildName"];////////模型
    //记录一个最初的状态，以防点击缺席后又点击取消缺席，我们却还是添加了VALUECHANGE字段。
    NSString * isChanged = [[NSString alloc]init];;
    if (model.IsAbsense) {
        isChanged = @"1";
    }else{
        isChanged = @"0";
    }
    
    if (!model.IsAbsense) {
        model.IsAbsense = YES;
        [self.dataArray removeObjectAtIndex:index.row];//将它删除从新加入==将它放在数组最后
        [self.dataArray addObject:dict];
        
        //将改变过得数据源从新存储到本地
        NSMutableDictionary * dictNew = [self.dataArray lastObject];
        ChildModel * mod = [dictNew objectForKey:@"ChildName"];
        for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
            if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                NSNumber * boolNum = [NSNumber numberWithBool:YES];
                [dic setObject:boolNum forKey:@"IsAbsense"];
                NSString * changed = @"1";
                if (![changed isEqualToString:isChanged]) {
                     [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
               
            }
        }
        //转换格式
        NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
        self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
        [user removeObjectForKey:@"AllData"];
        [user setObject:self.AllStr forKey:@"AllData"];
        [user synchronize];
        //得到已经测试的人数
        [self getData];
        NSInteger testedNum = [self getTestedBabyWithModelArray:_chosenChildArr andProjectArray:_projectArr];
        NSLog(@"testesd %ld",testedNum);
        self.processLabel.text = [NSString stringWithFormat:@"班级测试完成度(%ld/%ld)",testedNum,_chosenChildArr.count];

        [self.projectTable reloadData];
        [self.childTable reloadData];
        
    }else{
        model.IsAbsense = NO;
        //把字典里的数据换成改变后的
        [dict removeObjectForKey:@"ChildName"];
        [dict setObject:model forKey:@"ChildName"];
        //在DATAARRY里替换数据
        [self.dataArray replaceObjectAtIndex:index.row withObject:dict]
        ;
        
        //将改变过得数据源从新存储到本地
        NSMutableDictionary * dictNew = self.dataArray[index.row];
        ChildModel * mod = [dictNew objectForKey:@"ChildName"];
        for (NSMutableDictionary * dic in [_allDataDictionary objectForKey:@"Children"]) {
            if ([[dic objectForKey:@"ChildId"] isEqual:mod.ChildId]) {
                NSNumber * boolNum = [NSNumber numberWithBool:NO];
                [dic setObject:boolNum forKey:@"IsAbsense"];
                NSString * changed = @"0";
                if (![changed isEqualToString:isChanged]) {
                    [dic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
                }
                

                
            }
        }
        //转换格式
        NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
        self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
        [user removeObjectForKey:@"AllData"];
        [user setObject:self.AllStr forKey:@"AllData"];
        [user synchronize];
        //得到已经测试的人数
        [self getData];
        NSInteger testedNum = [self getTestedBabyWithModelArray:_chosenChildArr andProjectArray:_projectArr];
        NSLog(@"testesd %ld",testedNum);
        self.processLabel.text = [NSString stringWithFormat:@"班级测试完成度(%ld/%ld)",testedNum,_chosenChildArr.count];

        [self.projectTable reloadData];
        [self.childTable reloadData];
    }
    
    
    //让列表不要会第一列
    [self.childTable selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];
    [self.backView removeFromSuperview];
    [self.baseView removeFromSuperview];
}

#pragma mark 添加孩子
-(void)rightBarBtnClicked{
    NSLog(@"添加成员");
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    self.baseView = [[UIView alloc]init];
    self.baseView.backgroundColor = [UIColor whiteColor];
    [window addSubview:self.baseView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(window.mas_centerY);
        make.centerX.mas_equalTo(window.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 300*AutoScaleVertical));
    }];
    
    UILabel * label = [[UILabel alloc]init];
    label.text = @"添加孩子";
    label.textColor = [UIColor blackColor];
    [label setTextAlignment:NSTextAlignmentCenter];
    label.font = [UIFont boldSystemFontOfSize:15*AutoScaleHorizontal];
    [self.baseView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.baseView.mas_centerX);
        make.top.mas_equalTo(self.baseView.mas_top).with.offset(10*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    UIButton * cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelBtn setImage:[UIImage imageNamed:@"iconCancel"] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(pressCancel) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(label.mas_centerY);
        make.right.mas_equalTo(self.baseView.mas_right).with.offset(-30*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(30*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    UIView * lineview = [[UIView alloc]init];
    lineview.backgroundColor =UIColorFromRGB(243, 243, 243);
    [self.baseView addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.baseView);
        make.top.mas_equalTo(label.mas_bottom).with.offset(10*AutoScaleVertical);
        make.height.mas_equalTo(1*AutoScaleVertical);
    }];
    //////////////////////////////////////////////////////
    self.realNameLabel = [[UILabel alloc]init];
    self.realNameLabel.text = @"真实姓名";
    [self.realNameLabel setTextAlignment:NSTextAlignmentLeft];
    self.realNameLabel.textColor = UIColorFromRGB(79, 79, 79);
    self.realNameLabel.font = [UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [self.baseView addSubview:self.realNameLabel];
    [self.realNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.baseView.mas_left).with.offset(80*AutoScaleHorizontal);
        make.top.mas_equalTo(lineview.mas_bottom).with.offset(30*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(90*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.realNameIMG = [[UILabel alloc]init];
    self.realNameIMG.textColor =[UIColor redColor];
    self.realNameIMG.text = @"*";
    self.realNameIMG.font = [UIFont systemFontOfSize:15*AutoScaleHorizontal];
    [self.baseView addSubview:self.realNameIMG];
    [self.realNameIMG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.realNameLabel.mas_right);
        make.centerY.mas_equalTo(self.realNameLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 10*AutoScaleVertical));
    }];
    
    self.nameText = [[UITextField alloc]init];
    self.nameText.delegate =self;
    self.nameText.layer.borderWidth = 1;
    self.nameText.layer.borderColor =UIColorFromRGB(243, 243, 243).CGColor;
    [self.baseView addSubview:self.nameText];
    [self.nameText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.realNameIMG.mas_right);
        make.centerY.mas_equalTo(self.realNameLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.sexLabel = [[UILabel alloc]init];
    [self.sexLabel setTextAlignment:NSTextAlignmentLeft];
    self.sexLabel.text = @"性别";
    self.sexLabel.textColor = UIColorFromRGB(79, 79, 79);
    self.sexLabel.font = [UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [self.baseView addSubview:self.sexLabel];
    [self.sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.baseView.mas_left).with.offset(80*AutoScaleHorizontal);
        make.top.mas_equalTo(self.realNameLabel.mas_bottom).with.offset(40*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(90*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.sexIMG = [[UILabel alloc]init];
    self.sexIMG.textColor =[UIColor redColor];
    self.sexIMG.text = @"*";
    self.sexIMG.font = [UIFont systemFontOfSize:15*AutoScaleHorizontal];
    [self.baseView addSubview:self.sexIMG];
    [self.sexIMG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.sexLabel.mas_right);
        make.centerY.mas_equalTo(self.sexLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 10*AutoScaleVertical));
    }];
    
    self.boyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.boyBtn setTitle:@"男" forState:UIControlStateNormal];
    self.boyBtn.titleLabel.font =[UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [self.boyBtn addTarget:self action:@selector(pressBoy) forControlEvents:UIControlEventTouchUpInside];
    [self.boyBtn setTitleColor:UIColorFromRGB(79, 79, 79) forState:UIControlStateNormal];
    self.boyBtn.selected = YES;
    [self.boyBtn setImage:[UIImage imageNamed:@"manIMG"] forState:UIControlStateNormal];
    [self.boyBtn setImage:[UIImage imageNamed:@"manIMGS"] forState:UIControlStateSelected];
    [self.baseView addSubview:self.boyBtn];
    [self.boyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameText.mas_left).with.offset(30*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.sexLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(80*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.girlBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.girlBtn addTarget:self action:@selector(pressGirl) forControlEvents:UIControlEventTouchUpInside];
    [self.girlBtn setTitle:@"女" forState:UIControlStateNormal];
    self.girlBtn.titleLabel.font =[UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [self.girlBtn setTitleColor:UIColorFromRGB(79, 79, 79) forState:UIControlStateNormal];
    self.girlBtn.selected = NO;
    [self.girlBtn setImage:[UIImage imageNamed:@"womenIMG"] forState:UIControlStateNormal];
    [self.girlBtn setImage:[UIImage imageNamed:@"womenIMGS"] forState:UIControlStateSelected];
    [self.baseView addSubview:self.girlBtn];
    [self.girlBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.boyBtn.mas_right).with.offset(30*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.sexLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(80*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.birthLabel = [[UILabel alloc]init];
    [self.birthLabel setTextAlignment:NSTextAlignmentLeft];
    self.birthLabel.text = @"孩子生日";
    self.birthLabel.textColor = UIColorFromRGB(79, 79, 79);
    self.birthLabel.font = [UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [self.baseView addSubview:self.birthLabel];
    [self.birthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.baseView.mas_left).with.offset(80*AutoScaleHorizontal);
        make.top.mas_equalTo(self.sexLabel.mas_bottom).with.offset(40*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(90*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.birthIMG = [[UILabel alloc]init];
    self.birthIMG.textColor =[UIColor redColor];
    self.birthIMG.text = @"*";
    self.birthIMG.font = [UIFont systemFontOfSize:15*AutoScaleHorizontal];
    [self.baseView addSubview:self.birthIMG];
    [self.birthIMG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.birthLabel.mas_right);
        make.centerY.mas_equalTo(self.birthLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 10*AutoScaleVertical));
    }];
    
    self.birthDayLabel = [[UILabel alloc]init];
    self.birthDayLabel.layer.borderWidth = 1;
    self.birthDayLabel.layer.borderColor =UIColorFromRGB(243, 243, 243).CGColor;
    [self.birthDayLabel setTextAlignment:NSTextAlignmentCenter];
//    self.birthDayLabel.text = @"孩子生日";
    self.birthDayLabel.textColor = UIColorFromRGB(79, 79, 79);
    self.birthDayLabel.font = [UIFont systemFontOfSize:13*AutoScaleHorizontal];
    [self.baseView addSubview:self.birthDayLabel];
    [self.birthDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.birthIMG.mas_right);
        make.centerY.mas_equalTo(self.birthLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.birthDayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.birthDayBtn.backgroundColor = [UIColor clearColor];
    [self.birthDayBtn addTarget:self action:@selector(birthChoose) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:self. birthDayBtn];
    [self.birthDayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self.birthDayLabel);
    }];
    
    self.birthArrowIMG = [[UIImageView alloc]init];
    self.birthArrowIMG.image = [UIImage imageNamed:@"birthArrow"];
    [self.baseView addSubview:self.birthArrowIMG];
    [self.birthArrowIMG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.birthDayLabel.mas_right).with.offset(-15*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.birthLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 10*AutoScaleVertical));
    }];
    
    
    
    self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.confirmBtn addTarget:self action:@selector(pressConfirm) forControlEvents:UIControlEventTouchUpInside];
    [self.confirmBtn setBackgroundImage:[UIImage imageNamed:@"saveBtn"] forState:UIControlStateNormal];
    [self.baseView addSubview:self.confirmBtn];
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.baseView.mas_centerX);
        make.bottom.mas_equalTo(self.baseView.mas_bottom).with.offset(-20*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];


   
}

//点击生日调取日历
- (void)birthChoose{
    [self.nameText resignFirstResponder];
    _datePickerView = [[SDDatePickerView alloc]init];
    _datePickerView.delegate = self;
}
// 日历代理方法
-(void)cancelBtnClick{
    NSLog(@"取消日历");
}
- (void)sureBtnWithDate:(NSString *)dateStr
{
    NSLog(@"选择日历");
    self.birthDayLabel.text = dateStr;
}
-(void)pressBoy{
    [self.nameText resignFirstResponder];
    self.boyBtn.selected = YES;
    self.girlBtn.selected = NO;
}
-(void)pressGirl{
    [self.nameText resignFirstResponder];
    self.boyBtn.selected = NO;
    self.girlBtn.selected = YES;
}
//确认添加
-(void)pressConfirm{
    
    //找到当前正在更改的项目
    //    NSLog(@"保存%ld,%ld",self.intNum,self.theRow);
    NSIndexPath *index = [self.childTable indexPathForSelectedRow];
    NSMutableDictionary * dict = self.dataArray[index.row];
    ChildModel * model = [dict objectForKey:@"ChildName"];////////模型
    //取出当前班级和幼儿园ID
    NSNumber * classid = model.ClassId;
    NSNumber * kingid = model.KindergartenId;
    
    
    if (self.nameText.text == nil) {
        [self.nameText resignFirstResponder];
        [self showMessage:@"孩子姓名不能为空"];
    }
    else if (self.birthDayLabel.text == nil){
        [self.nameText resignFirstResponder];
        [self showMessage:@"孩子生日不能为空"];
    }else{
        //生成一个孩子字典
        
        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
        NSNumber * num = [user objectForKey:@"newChildId"];
        NSMutableDictionary * thisChildDic = [[NSMutableDictionary alloc]init];
        [thisChildDic setValue:classid forKey:@"ClassId"];
        [thisChildDic setValue:num forKey:@"ChildId"];
        [thisChildDic setValue:kingid forKey:@"KindergartenId"];
        [thisChildDic setValue:self.nameText.text forKey:@"ChildName"];
        [thisChildDic setValue:self.birthDayLabel.text forKey:@"Birthday"];
        [thisChildDic setValue:@"1" forKey:@"ValueChanged"];//如果改变了孩子，给本地数据加字段以便上传
        if (self.boyBtn.selected ==YES) {
            [thisChildDic setValue:@1 forKey:@"Gender"];
        }
        if (self.girlBtn.selected ==YES) {
            [thisChildDic setValue:@0 forKey:@"Gender"];
        }
        
        // 将孩子添加到当前页面数据源以用于刷新展示
        ChildModel * thisChildModel = [ChildModel modelWithDictionary:thisChildDic];
        ///////////////////////////获取选择好的项目
        NSMutableArray * arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"testProject"];//从本地取出项目组
        NSMutableArray * projectArr = [[NSMutableArray alloc] init];//用来装项目组的ARR
        for (NSArray * dataarr in arr) {
            NSMutableArray * proDetailArr = [[NSMutableArray alloc] init];
            for (NSDictionary * dic in dataarr) {
                NSMutableDictionary * dictt = [NSMutableDictionary dictionaryWithDictionary:dic];
                //            [dictt setValue:@10 forKey:@"proValue"];
                [proDetailArr addObject:dictt];
                
            }
            [projectArr addObject:proDetailArr];
        }
        NSMutableDictionary * dictionary = [[NSMutableDictionary alloc]init];
        [dictionary setValue:thisChildModel forKey:@"ChildName"];
        [dictionary setValue:projectArr forKey:@"Project"];
        [self.dataArray addObject:dictionary];
                //将新孩子存储到本地
        [[_allDataDictionary objectForKey:@"Children"] addObject:thisChildDic];
            //转换格式
            NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
            self.AllStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            [user removeObjectForKey:@"AllData"];
        
            NSInteger numint = [num integerValue] - 1;
            NSNumber  * newNum = [NSNumber numberWithInteger:numint];
            [user setObject:newNum forKey:@"newChildId"];
            [user setObject:self.AllStr forKey:@"AllData"];
            [user synchronize];
        [self.nameText resignFirstResponder];
        [self.backView removeFromSuperview];
        [self.baseView removeFromSuperview];
        //得到已经测试的人数
        [self getData];
        NSInteger testedNum = [self getTestedBabyWithModelArray:_chosenChildArr andProjectArray:_projectArr];
        NSLog(@"testesd %ld",testedNum);
        self.processLabel.text = [NSString stringWithFormat:@"班级测试完成度(%ld/%ld)",testedNum,_chosenChildArr.count];
        
            [self.childTable reloadData];
//        //默认选中第一行
        NSInteger selectNUm = 0;
        for (NSDictionary * dic in self.dataArray) {
            ChildModel * mod = [dic objectForKey:@"ChildName"];
            
            if (mod.IsAbsense) {
                break;
            }
            selectNUm +=1;
        }
        NSIndexPath *firstPath = [NSIndexPath indexPathForRow:selectNUm-1 inSection:0];
        [self.childTable selectRowAtIndexPath:firstPath animated:YES scrollPosition:UITableViewScrollPositionBottom];
        [self.projectTable reloadData];
    }
}
#pragma mark 导航左按钮方法
//系统返回按钮方法
-(void)leftBarBtnClicked{
    [self.navigationController popViewControllerAnimated:YES];
}
//导航右按钮

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark ---- 根据键盘高度将当前视图向上滚动同样高度
///键盘显示事件
- (void)keyboardWillShow:(NSNotification *)notification {
    //获取键盘高度，在不同设备上，以及中英文下是不同的
    CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
    
    //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
    CGFloat offset = kbHeight;
    
    // 取得键盘的动画时间，这样可以在视图上移的时候更连贯
    double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //将视图上移计算好的偏移
    if(offset > 0) {
        [UIView animateWithDuration:duration animations:^{
            //            self.baseView.frame = CGRectMake(0.0f, -100*AutoScaleVertical, self.baseView.frame.size.width, self.baseView.frame.size.height);
            UIWindow * window = [UIApplication sharedApplication].keyWindow;
            [self.baseView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(window.mas_top).with.offset(50*AutoScaleVertical);
                //                make.centerY.mas_equalTo(window.mas_centerY);
                make.centerX.mas_equalTo(window.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 300*AutoScaleVertical));
            }];
        }];
    }
}
#pragma mark ---- 当键盘消失后，视图需要恢复原状
///键盘消失事件
- (void)keyboardWillHide:(NSNotification *)notify {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    //视图下沉恢复原状
    [UIView animateWithDuration:duration animations:^{
        //        self.baseView.frame = CGRectMake(0, 0, self.baseView.frame.size.width, self.baseView.frame.size.height);
        UIWindow * window = [UIApplication sharedApplication].keyWindow;
        [self.baseView mas_remakeConstraints:^(MASConstraintMaker *make) {
            //            make.top.mas_equalTo(window.mas_top).with.offset(50*AutoScaleVertical);
            make.centerY.mas_equalTo(window.mas_centerY);
            make.centerX.mas_equalTo(window.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 300*AutoScaleVertical));
        }];
    }];
}
// 释放
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
    
    
}

#pragma mark 查找以测试人数
//得到已经测试人数的方法
-(NSInteger)getTestedBabyWithModelArray:(NSMutableArray *)modelArr andProjectArray:(NSMutableArray*)projectArr{
    NSInteger testedNum  = 0;
    
    for (int i = 0; i<modelArr.count; i++) {
        ChildModel * model = modelArr[i];
        int a = 0;//完成项目
        int b = 0;//有多少项目
        if (model.IsAbsense) {
            a = a+1;
            b = b+1;
        }else{
            for (NSMutableArray * arr in projectArr) {
                for (NSMutableDictionary * dict in arr) {
                    
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"1"]) {
                        if (model.Height !=nil) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"2"]) {
                        if (model.Weight !=nil) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"3"]) {
                        if ((model.IsMentalShuttleRun )||(model.IsMotorShuttleRun )||(model.ShuttleRun !=nil)) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"4"]) {
                        if ((model.IsMentalSitReach )||(model.IsMotorSitReach )||(model.SitReach !=nil)) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"5"]) {
                        if ((model.IsMentalBroadJump )||(model.IsMotorBroadJump )||(model.BroadJump !=nil)) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"6"]) {
                        if ((model.IsMentalDoubleJump )||(model.IsMotorDoubleJump )||(model.DoubleJump !=nil)) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"7"]) {
                        if ((model.IsMentalThrow )||(model.IsMotorThrow )||(model.Throw !=nil)) {
                            a= a+1;
                        }
                    }
                    if ([[dict objectForKey:@"proNum"]isEqualToString:@"8"]) {
                        if ((model.IsMentalBalance )||(model.IsMotorBalance )||(model.Balance !=nil)) {
                            a= a+1;
                        }
                    }
                    b++;
                }
            }}
            if(a == b){
                testedNum +=1;
        }
    }
    return testedNum;
    
}


#pragma mark  清除键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    return [textField resignFirstResponder];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES]; //实现该方法是需要注意view需要是继承UIControl而来的
}
// 需要使用的textfield遵循代理

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == self.textField) {
        return [self validateNumber:string];
    }
    return YES;
}
//筛选输入的内容  为数字
- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@".-0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
